package com.twotiger.and.activity.account.recharge;

import java.util.HashMap;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.twotiger.and.Constants;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.util.ViewUtils;

/**
 * 
 * @Description: 
 * 充值协议 
 * @Author douxy
 * @Date 2015年8月12日 下午1:52:37
 */
@SuppressLint("InflateParams")
public class RechargeProtocolPage extends BaseActivity implements OnClickListener, OnCheckedChangeListener {

    private static final int QUICKCHARGESUCCES = 0;
    private static final int QUICKCHARGEFAIL = 1;
    private CheckBox pro_sure_box;
    private Button pro_next_btn;
    private TextView textView;
    private boolean pro_next_btn_locked = true;

    private String amount;
    private String bankNid;
    private HashMap<String, String> params;
    private Handler handler;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.charge_pro_next:
            if (ViewUtils.isFastDoubleClick(view)) {
                return;
            }
            if (!pro_next_btn_locked) {
                params.clear();
                params.put("token", getToken());
                params.put("amount", amount);
                params.put("bankNid", bankNid);
                getDate(params, Constants.RECHARGE, handler, QUICKCHARGESUCCES, QUICKCHARGEFAIL, true, true, false);
                popBackStack();
            }
            break;
        case R.id.textView:
            if (ViewUtils.isFastDoubleClick(view)) {
                return;
            }
            pro_sure_box.toggle();
            break;
        default:
            break;
        }
    }

    @Override
    protected void setListener() {
        pro_sure_box.setOnCheckedChangeListener(this);
        pro_next_btn.setOnClickListener(this);
        textView.setOnClickListener(this);
    }

    @Override
    protected void processLogic() {
        params = getParm();
        amount = getIntent().getStringExtra("amount");
        bankNid = getIntent().getStringExtra("bankid");
        //		card = getIntent().getStringExtra("card");
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
        case R.id.charge_pro_btn:
            if (isChecked) {
                pro_next_btn.setBackgroundColor(getResources().getColor(R.color.black_99_color));
                pro_next_btn_locked = false;
            } else {
                pro_next_btn.setBackgroundColor(getResources().getColor(R.color.gray));
                pro_next_btn_locked = true;
            }
            break;
        default:
            break;
        }

    }

    @Override
    protected void findViewById(View view) {
        pro_sure_box = (CheckBox) view.findViewById(R.id.charge_pro_btn);
        pro_next_btn = (Button) view.findViewById(R.id.charge_pro_next);
        textView = (TextView) view.findViewById(R.id.textView);
    }

    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.charge_pro_layout, null);
        return view;
    }

    @Override
    protected void onBackPress() {
        // TODO Auto-generated method stub

    }

}
